package com.yantong.pay.yfz.pay;

import com.alibaba.fastjson.JSONObject;
import com.yantong.pojo.Centre;
import com.yantong.pojo.Order;
import com.yantong.utils.DateUtil;
import com.yantong.pay.yfz.domain.cust.CustHelper;
import com.yantong.pay.yfz.domain.cust.domain.business.apply.MerchantBusinessApplyRequest;
import com.yantong.pay.yfz.domain.cust.domain.business.apply.MerchantBusinessApplyResponse;
import com.yantong.pay.yfz.domain.cust.domain.business.entity.ApplySettleCycleEnum;
import com.yantong.pay.yfz.domain.cust.domain.business.entity.MerchantBusinessApply;
import com.yantong.pay.yfz.domain.cust.domain.business.entity.MerchantBusinessStage;
import com.yantong.pay.yfz.domain.cust.domain.business.modify.MerchantBusinessModifyRequest;
import com.yantong.pay.yfz.domain.cust.domain.business.modify.MerchantBusinessModifyResponse;
import com.yantong.pay.yfz.domain.cust.domain.business.query.MerchantBusinessQueryRequest;
import com.yantong.pay.yfz.domain.cust.domain.business.query.MerchantBusinessQueryResponse;
import com.yantong.pay.yfz.domain.cust.domain.merchant.request.CommodityInfo;
import com.yantong.pay.yfz.domain.cust.domain.merchant.request.SpAountSplitRequest;
import com.yantong.pay.yfz.domain.cust.domain.merchant.request.SpMerchantPaper;
import com.yantong.pay.yfz.domain.cust.domain.merchant.request.SpMerchantRequest;
import com.yantong.pay.yfz.domain.cust.domain.merchant.response.SpAountSplitResponse;
import com.yantong.pay.yfz.domain.cust.domain.merchant.response.SpMerchantApplyResponse;
import com.yantong.pay.yfz.domain.cust.domain.merchant.response.SpMerchantUpdateResponse;
import com.yantong.pay.yfz.domain.pay.domain.split.SplitInfo;
import com.yantong.pay.yfz.domain.pay.domain.withdraw.WithdrawToCardResponse;
import com.yantong.pay.yfz.util.HttpUtil;
import com.yantong.pay.yfz.util.KeyUtil;
import com.yantong.pay.yfz.util.RsaUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 平台商户进件接口测试（既可以进件标准商户又可以进件收单商户）
 *
 * @author fwy
 * @since 2019-5-8
 */
@Service
public class YFZSpMerchant {
	/**
	 * 标准商户进件申请(问题点：1、营业执照相片，需要提供真实的、2、对公账户文件需要盖章；3、开通微信支付，需要填写微信经营目录，需要开通支付宝业务，需要填写支付宝经营目录；4、提交商户时需同时提交对应需要开通的业务)
	 *
	 * @throws Exception
	 */
	public SpMerchantApplyResponse apply1() throws Exception {
		String version = "2.0";
		//真实的商户名称
		String merchantName = "广州琰通信息科技有限公司";
		String photo = "https://down.yantongtech.cn/data/upload/images/2020-11-27/ba9416412cf5d83eae1d735c47405dc4.png";

		SpMerchantRequest request = new SpMerchantRequest();
		request.setAcqSpId("562539003602372");// 必填，平台商户编号
//    	request.setAcqMerId("5651200003068224");//补件时上送
		request.setVersion(version);//版本号
		request.setBackUrl("");//选填，易票联审核完商户资料后的通知地
		request.setMerchantName(merchantName);//必填商户注册名称
		request.setAcceptOrder("1");//必填，是否收单：0：否，1：是,填0就是开通分账商户
		request.setOpenAccount("1");//必填，是否开户：0：否，1：是,填0就是开通简易商户，不开通简易商户
//    	request.setWechatChannelId("270952271");//选填，平台商户微信渠道号 对应：customer_extend_info
		request.setWechatBusinessId("758");//选填，微信经营类目ID,与 wechatChannelId同时存在
//    	request.setAlipayChannelId("2088721148870958");//选填，平台商户支付宝渠道号 。对应：customer_extend_info
//        request.setAlipayMcc("5411"); // 选填，支付宝MCC,与 alipayChannelId同时存在
		// 商户信息对象商户详细信息
		SpMerchantPaper paper = new SpMerchantPaper();
		// 基础信息
		paper.setMerchantType("2"); //必填 1：个体工商户  2：企业  3：个人(小微)
		paper.setBusinessLicenseCode("91440101MA5APWHG8L");//长度：13—18merchantType= 1、2 必传 营业执照号码
		paper.setBusinessLicenseName("广州琰通信息科技有限公司");//商户经营名称，与营业执照上登记注册的名称一致,merchantType= 1、2 必传
		String businessLicensePhoto = "https://down.yantongtech.cn/data/upload/images/2021-07-30/4feb7ede4e193ef1cb013f54f3659753.jpg";
		paper.setBusinessLicensePhoto(businessLicensePhoto); //merchantType= 1、2且openAccount=1时必传
		paper.setBusinessLicenseFrom("20180201");//merchantType= 1、2 必传。营业期限起始：格式：yyyymmdd
		paper.setBusinessLicenseTo("长期");//merchantType= 1、2 必传
		paper.setShortName("琰通标准商户");//标准商户必填
		paper.setIsCc("1"); // 营业执照类型：1：已三证合一；0：未三证合一，merchantType= 1、2 必传，3不必填
		paper.setLawyerName("魏娟");//法人姓名,merchantType= 1、2 必传，3不必填
		paper.setBusinessScope("软件和信息技术服务业"); //merchantType= 1、2 必传，经营范围，3不必填
		paper.setRegisterAddress("广州市白云区永平街永泰永康南路12号410房");//注册地址：merchantType= 1、2 必传，3不必填
//		paper.setOrganizationCode("91440101MA5APWHG8L");//组织机构代码,merchantType= 1、2且isCc=0时必传，3不必填
//		paper.setOrganizationCodePhoto(photo);//组织机构代码照片merchantType= 1、2且isCc=0时必传，3不必填
//		paper.setOrganizationCodeFrom("20180201");//组织机构代码有效期（起始）,merchantType= 1、2且isCc=0时必传，3不必填
//		paper.setOrganizationCodeTo("长期");//组织机构代码有效期（截止）,merchantType= 1、2且isCc=0时必传，3不必填
////    	 位置及环境信息
		paper.setBusinessAddress("广州市白云区永平街永泰永康南路12号410房");//标准商户必填
		paper.setProvince("440000");//标准商户必填
		paper.setCity("440100");//标准商户必填
		paper.setArea("440111");//标准商户必填
		paper.setMcc("5399");//标准商户必填
		paper.setUnionShortName("");//银联快捷简称,需开通银联快捷相关业务时必填，不填的话就只能取二维码的号了
		String storeHeadPhoto = "https://down.yantongtech.cn/data/upload/images/2021-07-28/f3a4f51dd2b4223119c509c3e2f7a399.jpg";
		String storeShopPhoto = "https://down.yantongtech.cn/data/upload/images/2021-07-28/092c2c7a780e9a95f02cf7348b490d1c.jpg";
		String storeHallPhoto = "https://down.yantongtech.cn/data/upload/images/2021-07-28/c7493931806cce00c63513c13f98f398.jpg";
		paper.setStoreHeadPhoto(storeHeadPhoto);//商户类型12必填，3 不填
		paper.setStoreShopPhoto(storeShopPhoto);//商户类型123都不用填了
		paper.setStoreHallPhoto(storeHallPhoto);//商户类型12必填，3 不填
		//paper.setStoreCashierPhoto(photo);//商户类型123都不用填了了
		// 法人资料信息
		String lawyerCertPhotoFront = "https://down.yantongtech.cn/data/upload/images/2021-07-28/2958213ea4cc6724d764b16ed300fc4f.jpg";
		String lawyerCertPhotoBack = "https://down.yantongtech.cn/data/upload/images/2021-07-28/a9b86b485f5a111dbc20a059dd63b4b3.jpg";
		paper.setLawyerCertType("0");// 0：身份证,目前仅支持0身份证、3护照，
		paper.setLawyerCertNo("431126198211210048");//法人证件号码强制必传
		paper.setLawyerCertPhotoFront(lawyerCertPhotoFront);//标准商户必填 身份证正面
		paper.setLawyerCertPhotoBack(lawyerCertPhotoBack);//标准商户必填  身份证反面
		paper.setCertificateName("魏娟");//必填证件人姓名,merchantType=1、2时，等于lawyerName,为3时不用等于
		paper.setCertificateFrom("20210720");//标准商户必填
		paper.setCertificateTo("20410720");//标准商户必填
		// 联系人信息
		paper.setContactPerson("魏娟");//标准商户必填
		paper.setContactPhone("15915884688");//联系人手机号码标准商户必填
		paper.setServiceTel("15915884688");//客服电话，标准商户必填
		paper.setEmail("16553389@qq.com");//邮箱地址，标准商户必填
//    	 开户许可证信息
		paper.setLicenceAccount(merchantName); // 非必填，开户许可证账户名，必须与商户名称一致 开户许可证账户名（需与商户名一致）
		paper.setLicenceAccountNo("3602061009200317466");//非必填,开户许可证账号
		paper.setLicenceOpenBank("中国工商银行");//非必填,开户许可证开户银行，openAccount=1时必传
		paper.setLicenceOpenSubBank("中国工商银行股份有限公司广州黄埔大道西支行");//非必填,开户许可证开户支行
		String openingLicenseAccountPhoto = "https://down.yantongtech.cn/data/upload/images/2021-07-28/24de092dfe1296f61d11752cde9fe349.jpg";
		paper.setOpeningLicenseAccountPhoto(openingLicenseAccountPhoto);//非必填，开户许可证（照片）
//    	 结算账户信息
		paper.setSettleAccountType("1"); // openAccount=1时必传，1：对公账户  2：法人账户
		//3：被授权人对公账户   4:被授权人对私账户  	merchantType=3 时必填 2 , 被授权人3 和4 不做校验
		paper.setSettleAccountNo("6222083602013190605");//openAccount=1时必传结算户号
		paper.setSettleAccount(merchantName);//openAccount=1时必传；
//    	merchantType=1、2且：settleAccountType=1时，需与商户名称merchantName一致；
//    	merchantType=1、2且：settleAccountType=2时，需与法人姓名lawyerName一致；
//    	merchantType=3时，需与certificateName一致。
		paper.setSettleTarget("2"); // 有条件选填，openAccount=1时必传，提现方式，1：自动提现；2：手动提现
		String bankCardPhotoFront = "";
		String bankCardPhotoBack = "";
//		paper.setBankCardPhotoFront(bankCardPhotoFront);//银行卡正面照,settleAccountType=2时 openAccount=1必传
//		paper.setBankCardPhotoBack(bankCardPhotoBack);//银行卡背面照,非必填
		paper.setOpenBank("中国工商银行");//有条件选填，开户银行，openAccount=1时必传
		paper.setOpenSubBank("中国工商银行股份有限公司广州黄埔大道西支行");//开户支行,settleAccountType为“1：对公账户”时必填
		paper.setOpenBankCode("102581000798");//开户行联行号,settleAccountType为“1：对公账户”时必填，参见附件支行及联行号
		paper.setOpenBankReservePhone("15915884688");//非必填，银行预留手机号
		// 其他附件
//		List<String> otherPhoto = new ArrayList<String>();
//		otherPhoto.add(photo);
//		otherPhoto.add(photo);
//		paper.setOtherPhoto(otherPhoto);

		request.setPaper(paper.toString());

		//业务申请请求
		List<MerchantBusinessApply> businessList = new ArrayList<MerchantBusinessApply>();
//        businessList.add(newBusiness("WITHDRAW", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
//       businessList.add(newBusiness("WITHDRAW_CREDIT_CARD", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
		//交易分账
		businessList.add(newBusiness("TRADE_SPLIT", null, 0L, ApplySettleCycleEnum.SETTLECYCLE_D0));
		//账户分账
		businessList.add(newBusiness("ACCOUNT_SPLIT", null, 0L, ApplySettleCycleEnum.SETTLECYCLE_D0));
		//微信主扫
		businessList.add(newBusiness("WX_NATIVE_PAY", 26L, null, ApplySettleCycleEnum.SETTLECYCLE_T1));
		//微信被扫
		businessList.add(newBusiness("WX_MICRO_PAY", 26L, null, ApplySettleCycleEnum.SETTLECYCLE_T1));
		//公众号支付
		businessList.add(newBusiness("WX_JSAPI_PAY", 26L, null, ApplySettleCycleEnum.SETTLECYCLE_T1));
		//小程序支付
		businessList.add(newBusiness("WX_MINI_PROGRAM", 26L, null, ApplySettleCycleEnum.SETTLECYCLE_T1));
		//businessList.add(newBusiness("ALI_NATIVE_PAY", 50L, null, ApplySettleCycleEnum.SETTLECYCLE_D0));
        /*
        businessList.add(newBusiness("ALI_MICRO_PAY", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("ALI_JSAPI_PAY", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("UNION_SWEEP", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("UNION_QRCODE", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("UNION_ONLINE", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("UNION_ONLINE_CREDIT", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("PROTOCOL_PAY", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("PROTOCOL_PAY_CREDIT", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("ENTERPRISE_UNION", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("QUICK_PAY", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
        businessList.add(newBusiness("QUICK_PAY_CREDIT", BigDecimal.ONE, 1L, ApplySettleCycleEnum.SETTLECYCLE_D0));
*/
		request.setBusiness(businessList);
		SpMerchantApplyResponse resp = CustHelper.spMerchantApply(request, "user-rsa.pfx", "yt2021@", "562539003602372001", "efps.cer");

		System.out.println("响应报文:" + JSONObject.toJSONString(resp));
		return resp;
	}

	/**
	 * 分账商户进件申请（不收单商户）
	 * 注：(一个身份证最多只能进件三次，否则报异常{"respCode":"11226","respMsg":"商户证件信息已存在","acqSpId":null,"acqMerId":null,"merId":null})
	 *
	 * @param acqSpId         平台商户编号
	 * @param merchantName    真实姓名
	 * @param lawyerCertNo    身份证
	 * @param contactPhone    手机号码
	 * @param email           邮箱
	 * @param settleAccountNo 银行卡号
	 * @param openBank        银行卡总行名称
	 * @return com.yantong.pay.yfz.domain.merchant.response.SpMerchantApplyResponse
	 * @author liaozhaogui
	 * @date 2021/7/26 17:38
	 */
	public SpMerchantApplyResponse apply2(String acqSpId, String merchantName, String lawyerCertNo, String contactPhone, String email, String settleAccountNo, String openBank) throws Exception {
		String version = "2.0";
		//url的图片
		String photo = "https://down.yantongtech.cn/data/upload/images/2020-11-27/ba9416412cf5d83eae1d735c47405dc4.png";
		SpMerchantRequest request = new SpMerchantRequest();
		// 必填，平台商户编号
		request.setAcqSpId(acqSpId);
		//版本号
		request.setVersion(version);
		//选填，易票联审核完商户资料后的通知地
		request.setBackUrl("");
		//必填商户注册名称
		request.setMerchantName(merchantName);
		//必填，是否收单：0：否，1：是,填0就是开通分账商户
		request.setAcceptOrder("0");
		//必填，是否开户：0：否，1：是,填0就是开通简易商户，不开通简易商户
		request.setOpenAccount("1");
		// 商户信息对象商户详细信息
		SpMerchantPaper paper = new SpMerchantPaper();
		// 基础信息-------------------------------------
		// 必填，1：个体工商户  2：企业  3：个人(小微)
		paper.setMerchantType("3");
		// 法人资料信息-------------------------------------
		// 必填，0：身份证,目前仅支持0身份证、3护照，
		paper.setLawyerCertType("0");
		//法人证件号码强制必传
		paper.setLawyerCertNo(lawyerCertNo);
		//证件人姓名,强制必传，merchantType=1、2时，等于lawyerName ，3时可以不等于？
		paper.setCertificateName(merchantName);
		// 联系人信息-------------------------------------
		//分账必填
		paper.setContactPhone(contactPhone);
		//分账商户123 都不用填
		paper.setEmail("16553389@qq.com");
		//开户许可证信息-------------------------------------
		//merchantType=2且settleAccountType=2时必传，为3不填
		paper.setOpeningLicenseAccountPhoto(photo);
//    	 结算账户信息-------------------------------------
		// 必填，1：对公账户  2：法人账户  3：被授权人账户 	merchantType=3 时必填 2
		paper.setSettleAccountType("2");
		//分账必填
		paper.setSettleAccountNo(settleAccountNo);
		//分账必填
		paper.setSettleAccount(merchantName);
		// 分账必传，提现方式，1：自动提现；2：手动提现
		paper.setSettleTarget("2");
		//分账必传
		paper.setOpenBank(openBank);
		request.setPaper(paper.toString());

		//业务申请请求
		List<MerchantBusinessApply> businessList = new ArrayList<MerchantBusinessApply>();
		//账户分账
		businessList.add(newBusiness("ACCOUNT_SPLIT", null, 0L, ApplySettleCycleEnum.SETTLECYCLE_D0));
		request.setBusiness(businessList);
		SpMerchantApplyResponse resp = CustHelper.spMerchantApply(request, "user-rsa.pfx", "yt2021@", "562539003602372001", "efps.cer");
		System.out.println("响应报文:" + JSONObject.toJSONString(resp));
		return resp;
	}

	private MerchantBusinessApply newBusiness(String businessCode, Long feeRate,
	                                          Long feePer, ApplySettleCycleEnum settlecycle) {
		//申请开通业务
		//阶梯手续费费率
		MerchantBusinessStage stage = new MerchantBusinessStage();
		stage.setFeeRate(feeRate);
		stage.setFeePer(feePer);
//        stage.setAmountFrom(99999999999L);

//        MerchantBusinessStage stage2 = new MerchantBusinessStage();
//      stage.setFeeRate(feeRate);
//      stage2.setFeePer(feePer);
		//     stage2.setAmountFrom(99999999999L);

		MerchantBusinessApply business = new MerchantBusinessApply();
		business.setBusinessCode(businessCode);
		business.setSettleCycle(settlecycle);
		business.getStage().add(stage);
		return business;
	}


	/**
	 * 更新商户会员
	 *
	 * @throws Exception
	 */
	public void update() throws Exception {
//    	String photo = "https://www.epaylinks.cn/www/wimages/epl_logo.png";

		SpMerchantRequest request = new SpMerchantRequest();
		request.setVersion("2.0");//版本号，必填
		request.setAcqSpId("562769003068874");// 平台商户编号,必填
		request.setAcqMerId("562137003095173");//商户编号,必填
//    	request.setBackUrl("http://www.baidu.com");//审核回调地址,非必填
//    	request.setMerchantName("易票联标准7");//商户注册名称,非必填
//    	request.setWechatChannelId("270952271");//选填，进件未填时可补，平台商户微信渠道号 对应：customer_extend_info
//    	request.setWechatBusinessId("291");//选填，进件未填时可补，微信经营类目ID,与 wechatChannelId同时存在
//    	request.setAlipayChannelId("2088721148870958");//选填，进件未填时可补，平台商户支付宝渠道号 。对应：customer_extend_info
//        request.setAlipayMcc("5411"); // 选填，进件未填时可补，支付宝MCC,与 alipayChannelId同时存在
		// 商户商户详细信息,JSON格式
		SpMerchantPaper paper = new SpMerchantPaper();
		//商户基础信息
//    	paper.setBusinessLicensePhoto(photo);//营业执照照片,非必填
//    	paper.setBusinessLicenseFrom("20190826");//营业执照有效期（起始）,非必填
//    	paper.setBusinessLicenseTo("20190826");//营业执照有效期（截止）,非必填
//    	paper.setShortName("我就只改一个简称而已");//商户简称,最长8个汉字,选填
//    	paper.setIsCc("1"); // 营业执照类型：1：已三证合一；0：未三证合一，选填
//    	paper.setBusinessScope("经营范围不知道啊"); //经营范围，非必填
//    	paper.setRegisterAddress("432");//注册地址：非必填
//    	paper.setOrganizationCode("");//组织机构代码,非必填
//    	paper.setOrganizationCodePhoto(photo);//组织机构代码照片,非必填
//    	paper.setOrganizationCodeFrom("");//组织机构代码有效期（起始）,非必填
//    	paper.setOrganizationCodeTo("");//组织机构代码有效期（截止）,非必填
//    	// 位置及环境信息
//    	paper.setBusinessAddress("广东省广州市天河区广州大道南369号");//营业地，可以不同注册地址，,非必填
//    	paper.setProvince("440000");//非必填省
//    	paper.setCity("440100");//,非必填，市
//    	paper.setArea("440106");//,非必填，区，	
//    	paper.setMcc("5521");//修改时非必填，进件未填时可补
//    	paper.setUnionShortName("银联快捷简称简称");//需开通银联快捷相关业务时必填   最长8个汉字
//    	paper.setStoreHeadPhoto(photo);//门店门头照,非必填，openAccount=1时必传
//    	paper.setStoreShopPhoto(photo);//门店外景照,非必填
//    	paper.setStoreHallPhoto(photo);//门店内景照,非必填，openAccount=1时必传
//    	paper.setStoreCashierPhoto(photo);//门店收银台照,非必填
		// 个人资料信息
//    	paper.setLawyerCertType("0");// 0：身份证,目前仅支持0：强制必传
//    	paper.setLawyerCertNo("111020199901018225");//法人证件号码，选填
//    	paper.setLawyerCertPhotoFront(photo);//非必填，法人证件正面照
//    	paper.setLawyerCertPhotoBack(photo);//非必填，法人证件反面照
//    	paper.setCertificateName("法人张三丰");//证件人姓名,非必填
//    	paper.setCertificateFrom("20190122");//证件效期(起始),非必填，主要给乐云付简易商户用
//    	paper.setCertificateTo("20190122");//证件效期(截止),非必填，主要给乐云付简易商户用
		// 联系人信息
//    	paper.setContactPerson("张豪");//非必填
//    	paper.setContactPhone("13590001111");//非必填
//    	paper.setServiceTel("40012345678");//非必填
//    	paper.setEmail("zhangping@epaylinks.cn");//非必填
		// 开户许可证信息
//    	paper.setLicenceAccount(merchantName); // 非必填，开户许可证账户名，必须与商户名称一致 开户许可证账户名（需与商户名一致）
//    	paper.setLicenceAccountNo("12345678000");//非必填,开户许可证账号
//    	paper.setLicenceOpenBank("");//非必填,开户许可证开户银行
//    	paper.setLicenceOpenSubBank("中国银行股份有限公司广州中山八路支行");//非必填,开户许可证开户支行
//    	paper.setOpeningLicenseAccountPhoto(photo);//非必填，开户许可证（照片）
		// 结算账户信息
		paper.setSettleAccountType("2"); // 非必填，1：对公账户  2：法人账户  3：被授权人账户 	merchantType=3 时必填 2
		paper.setSettleAccountNo("54554545454545454");//非必填必传结算户号
		paper.setSettleAccount("分账092170");//非必填；
////    	merchantType=1、2且：settleAccountType=1时，需与商户名称merchantName一致；
////    	merchantType=1、2且：settleAccountType=2时，需与法人姓名lawyerName一致；
////    	merchantType=3时，需与certificateName一致。
		paper.setSettleTarget("1"); // 非必填提现方式，1：自动提现；2：手动提现
//    	paper.setBankCardPhotoFront(photo);//银行卡正面照,ettleAccountType=2时 必传
//    	paper.setBankCardPhotoBack(photo);//银行卡背面照,非必填
		paper.setOpenBank("中国银行");//有条件选填，开户银行，openAccount=1时必传
		paper.setOpenSubBank("中国银行股份有限公司广州中山八路支行");//开户支行,settleAccountType为“1：对公账户”时必填
		paper.setOpenBankCode("104581004181");//开户行联行号,settleAccountType为“1：对公账户”时必填，参见附件支行及联行号
//    	paper.setOpenBankReservePhone("13400001111");//非必填，银行预留手机号

		request.setPaper(paper.toString());
		SpMerchantUpdateResponse resp = CustHelper.spMerchantUpdate(request, "user-rsa.pfx", "yt2021@", "562539003602372001", "efps.cer");
		System.out.println("响应报文:" + JSONObject.toJSONString(resp));

	}


	/**
	 * 绑定授权目录
	 *
	 * @param acqSpId   平台商户编号
	 * @param acqMerId  商户编号
	 * @param jsapiPath 授权目录
	 * @author liaozhaogui
	 * @date 2021/7/30 10:22
	 */
	public void jsapiPath(String acqSpId, String acqMerId, String jsapiPath, String yplPrivateKey, String yplPrivateKeyPwd, String yplSignNo, String yplPublicKey) throws Exception {
		Map<String, String> map = new HashMap<>();
		map.put("version", "2.0");
		map.put("acqSpId", acqSpId);
		map.put("acqMerId", acqMerId);
		map.put("jsapiPath", jsapiPath);
		map.put("yplPrivateKey", yplPrivateKey);
		map.put("yplPrivateKeyPwd", yplPrivateKeyPwd);
		map.put("yplSignNo", yplSignNo);
		map.put("yplPublicKey", yplPublicKey);
		String nowtime = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
		//签名
		final String sign = RsaUtils.sign(KeyUtil.getPrimaryKey(map.get("yplPrivateKey"), map.get("yplPrivateKeyPwd")), JSONObject.toJSONString(map));
		Map<String, String> header = new HashMap<>();
		header.put("x-efps-sign", sign);
		header.put("x-efps-sign-no", map.get("yplSignNo"));
		header.put("x-efps-sign-type", "SHA256withRSA");
		header.put("x-efps-timestamp", nowtime);
		header.put("Content-Type", "application/json");
		String url = "http://efps.epaylinks.cn/api/cust/wechat/wechatConfig/jsapiPath";
		Object obj = HttpUtil.post(url, JSONObject.toJSONString(map), header, WithdrawToCardResponse.class, map.get("yplPublicKey"));
		System.out.println("响应报文:" + JSONObject.toJSONString(JSONObject.toJSONString(obj)));
	}

	/**
	 * 绑定Appid
	 *
	 * @param acqSpId  平台商户编号
	 * @param acqMerId 商户编号
	 * @param subAppid appid
	 * @author liaozhaogui
	 * @date 2021/7/30 10:22
	 */
	public void subAppid(String acqSpId, String acqMerId, String subAppid, String yplPrivateKey, String yplPrivateKeyPwd, String yplSignNo, String yplPublicKey) throws Exception {
		Map<String, String> map = new HashMap<>();
		map.put("version", "2.0");
		map.put("acqSpId", acqSpId);
		map.put("acqMerId", acqMerId);
		map.put("subAppid", subAppid);
		map.put("yplPrivateKey", yplPrivateKey);
		map.put("yplPrivateKeyPwd", yplPrivateKeyPwd);
		map.put("yplSignNo", yplSignNo);
		map.put("yplPublicKey", yplPublicKey);
		String nowtime = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
		//签名
		final String sign = RsaUtils.sign(KeyUtil.getPrimaryKey(map.get("yplPrivateKey"), map.get("yplPrivateKeyPwd")), JSONObject.toJSONString(map));
		Map<String, String> header = new HashMap<>();
		header.put("x-efps-sign", sign);
		header.put("x-efps-sign-no", map.get("yplSignNo"));
		header.put("x-efps-sign-type", "SHA256withRSA");
		header.put("x-efps-timestamp", nowtime);
		header.put("Content-Type", "application/json");
		String url = "http://efps.epaylinks.cn/api/cust/wechat/wechatConfig/subAppid";
		Object obj = HttpUtil.post(url, JSONObject.toJSONString(map), header, WithdrawToCardResponse.class, map.get("yplPublicKey"));
		System.out.println("响应报文:" + JSONObject.toJSONString(JSONObject.toJSONString(obj)));
	}

	/**
	 * 商户业务查询
	 */
	public static MerchantBusinessQueryResponse merchantBusinessQuery(Centre centre) throws Exception {
		MerchantBusinessQueryRequest request = new MerchantBusinessQueryRequest();
		request.setAcqSpId(centre.getYplCustomerCode());
		request.setAcqMerId(centre.getYplSignNo());
		return CustHelper.merchantBusinessQuery(request, centre.getYplPrivateKey(), centre.getYplPrivateKeyPwd(), centre.getYplSignNo(), centre.getYplPublicKey());
	}

	/**
	 * 账户分账
	 */
	public SpAountSplitResponse accountSplit(Order order, Centre centre, String splitCustomerCode) throws Exception {
//		String customerCode = order.getypl;
		String commodityOrderTime = DateUtil.convertDateToString(order.getPayTime(), "YYYYMMDDHHMMSS");
		String sn = RandomStringUtils.randomAlphanumeric(10);
		String outTradeNo = "a_sl_".concat(sn);
		Long commodityAmount = new BigDecimal("2.5").multiply(new BigDecimal(100)).longValue();
		List<CommodityInfo> commodityInfoList = new ArrayList<>();
		commodityInfoList.add(new CommodityInfo(order.getPayno(), commodityAmount, commodityOrderTime, "大礼包"));

		List<SplitInfo> splitInfoList = new ArrayList<>();
		splitInfoList.add(new SplitInfo(centre.getYplCustomerCode(), new BigDecimal("1.1").multiply(new BigDecimal(100)).longValue(), 3));

		String notifyUrl = "www.baidu.com";
		String attachData = "aaa";
		String nonceStr = UUID.randomUUID().toString().replaceAll("-", "");

		SpAountSplitRequest request = new SpAountSplitRequest();
		request.setCustomerCode(splitCustomerCode);
		request.setOutTradeNo(outTradeNo);
		request.setCommodityAmount(commodityAmount);
		request.setCommodityInfoList(commodityInfoList);
		request.setSplitInfoList(splitInfoList);
		request.setNotifyUrl(notifyUrl);
		request.setAttachData(attachData);
		request.setNonceStr(nonceStr);


		System.out.println("请求参数:" + JSONObject.toJSONString(request));
		SpAountSplitResponse resp = CustHelper.accountSplitQuery(request, centre.getYplPrivateKey(), centre.getYplPrivateKeyPwd(), centre.getYplSignNo(), centre.getYplPublicKey());

		System.out.println("响应报文:" + JSONObject.toJSONString(resp));
		return resp;
	}

	/**
	 * 商户业务修改
	 *
	 * @return
	 * @throws Exception
	 */
	public MerchantBusinessModifyResponse merchantBusinessModify(Centre centre, String customerCode) throws Exception {

//		// 阶梯手续费费率
//		MerchantBusinessStage stage = new MerchantBusinessStage();
//		stage.setFeeRate(0L);
//
//		// 申请开通业务
//		MerchantBusinessApply apply = new MerchantBusinessApply();
//		apply.setBusinessCode("ACCOUNT_SPLIT");
//		apply.setSettleCycle(ApplySettleCycleEnum.SETTLECYCLE_D0);
//		apply.getStage().add(stage);

		//业务申请请求
		List<MerchantBusinessApply> businessList = new ArrayList<MerchantBusinessApply>();
		//账户分账
		businessList.add(newBusiness("ACCOUNT_SPLIT", null, 0L, ApplySettleCycleEnum.SETTLECYCLE_D0));
		// 业务申请请求
		MerchantBusinessModifyRequest request = new MerchantBusinessModifyRequest();
		request.setAcqSpId(centre.getYplCustomerCode());
		request.setAcqMerId(customerCode);
		request.setBusiness(businessList);
		MerchantBusinessModifyResponse merchantBusinessModifyResponse = CustHelper.merchantBusinessModify(request, centre.getYplPrivateKey(), centre.getYplPrivateKeyPwd(), centre.getYplSignNo(), centre.getYplPublicKey());
		return merchantBusinessModifyResponse;
	}

	/**
	 * 商户业务申请
	 */
	public MerchantBusinessApplyResponse merchantBusinessApply(Centre centre, String customerCode) throws Exception {
		//业务申请请求
		List<MerchantBusinessApply> businessList = new ArrayList<MerchantBusinessApply>();
		//账户分账
		businessList.add(newBusiness("ACCOUNT_SPLIT", null, 0L, ApplySettleCycleEnum.SETTLECYCLE_D0));

		// 业务申请请求
		MerchantBusinessApplyRequest request = new MerchantBusinessApplyRequest();
		request.setAcqSpId(centre.getYplCustomerCode());
		request.setAcqMerId(customerCode);
		request.setBusiness(businessList);
		MerchantBusinessApplyResponse merchantBusinessApplyResponse = CustHelper.merchantBusinessApply(request, centre.getYplPrivateKey(), centre.getYplPrivateKeyPwd(), centre.getYplSignNo(), centre.getYplPublicKey());
		return merchantBusinessApplyResponse;
	}

}
